<?php
	require_once('db_connect.php');
	$user_id = $_POST['user_id'];
	$lat = $_POST['lat'];
	$lng = $_POST['lng'];
	
	$query = "select * from session where user_id='$user_id'";
	$result = mysqli_query($conn, $query);

	if (mysqli_num_rows($result) > 0) {
		$query = "UPDATE session SET lat = '$lat', lng = '$lng' WHERE user_id = '$user_id'";
		mysqli_query($conn, $query)
			or die('session 업데이트 쿼리 실패');
		echo json_encode(array('status' => '0'));
		exit;
	}
	else {
		$query = "insert into session(user_id, lat, lng) values('$user_id', '$lat', '$lng')";
		mysqli_query($conn, $query)
			or die('session 삽입 쿼리 실패');
		echo json_encode(array('status' => '0'));
		exit;
	}
?>